"""
演示RDD对象输出数据到文件
"""

from pyspark import SparkContext,SparkConf
import os
import json
os.environ["HADOOP_HOME"] = "D:/dev/spark-3.3.1-bin-hadoop3"
os.environ["PYSPARK_PYTHON"] = "C:/Users/86131/AppData/Local/Programs/Python/Python39/python.exe"
conf = SparkConf().setMaster("local[*]").setAppName("test_spark")
conf.set("spark.default.parallelism","1")
sc = SparkContext(conf=conf)

#准备RDD1
rdd1 = sc.parallelize([1, 2, 3, 4, 5],numSlices=1)

#准备RDD2
rdd2 = sc.parallelize([("hello", 1), ("itheima", 2), ("itcast", 3)],numSlices=1)
#准备RDD3
rdd3 = sc.parallelize([[1, 3, 4], [2, 3, 5]],numSlices=1)


#输出到文件中
rdd1.saveAsTextFile("D:/output1")
rdd2.saveAsTextFile("D:/output2")
rdd3.saveAsTextFile("D:/output3")


